<template>
	<view>
		<user v-if="type==0 || type==1"></user>
		<worker v-if="type==2"></worker>
	</view>
</template>

<script>
	import user from "../user/index"
	import worker from "../worker/worker"
	export default {
		components: {
			user,
			worker
		},
		data() {
			return {
				active: '0',
				key: '',
				deviceList: [],
				deviceId: 0,
				isTo: false,
				scene: "",


			}
		},
		computed: {
			type() {
				return this.$store.state.user.info.type
			}
		},
		watch: {
			type() {
				if (this.deviceId && !this.isTo) {
					this.navTo()
				}
			}
		},
		onLoad(options) {
			if (options.scene) {
				const data = decodeURIComponent(options.scene)
				console.log(data, options.scene)
				const arr = data.split('=')
				if (arr.length > 1) {
					this.deviceId = arr[1]
					if (!this.isTo && (this.type === 0 || this.type == 1 || this.type == 2)) {
						this.navTo()
					}
				}

			}
		},
		onShow() {

		},
		created() {
			
		},
		methods: {
			navTo() {
				this.isTo = true
				if (this.type == 2) {
					this.$func.toUrl('/pages_worker/index/index?device_id=' + this.deviceId)
				} else {
					uni.showLoading({
						title: "请稍等"
					})
					this.$http.post('/data/api.auth.User/deviceVier', {
						id: this.deviceId
					}).then(rest => {
						uni.hideLoading()
						if (rest.data.device_status == 3) {
							this.$func.tips(rest.data.device_name + '已报废')
						} else {
							this.$func.toUrl('/pages_user/repair/add?id=' + this.deviceId)
							// this.$func.toUrl('/pages_user/device/detail?id=' + this.deviceId)
						}
					}).catch(e => {
						uni.hideLoading()
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">

</style>